package com.example.projecth.projecthealth;


import com.example.projecth.R;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.app.Fragment;
import android.content.Context;

public class MainActivity extends Activity  {

//	private ViewPager pager;
	private Fragment[] fragments;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.jsactivity_main);

		fragments = new Fragment[2];
		fragments[0] = new CalorieFragment();
		fragments[1] = new MyOnedayFragment();
		
		ActionBar bar = getActionBar();
		
		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		
		bar.addTab(bar.newTab().setText("칼로리 계산기").setTabListener(listener));
		bar.addTab(bar.newTab().setText("나의 하루 칼로리").setTabListener(listener));
		
		bar.selectTab(bar.getTabAt(0));
		
//		pager = (ViewPager)findViewById(R.id.pager);
//		pager.setAdapter(new MyPagerAdapter(this));
		
	}
	
	private TabListener listener = new TabListener() {
		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		}
		
		@Override
		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			ft.replace(R.id.fragment_container, fragments[tab.getPosition()]);
//			if () {
//				
//			}
		}
		
		@Override
		public void onTabReselected(Tab tab, FragmentTransaction ft) {
		}
	};
	
	
//	class MyPagerAdapter extends PagerAdapter {
//
//		Context context;
//		LayoutInflater inflater;
//		View[] views = new View[2];
//		
//		public MyPagerAdapter() {
//		}
//
//		public MyPagerAdapter(Context context) {
//			this.context = context;
//			inflater = LayoutInflater.from(context);
//		}
//
//		@Override
//		public int getCount() {
//			return views.length;// 표시할 화면의 갯수
//		}
//
//		@Override
//		public boolean isViewFromObject(View arg0, Object arg1) {
//			return (arg0 == arg1);// View의 타당성 체크
//		}
//
//		// View 생성 및 반환 메서드
//		@Override
//		public Object instantiateItem(ViewGroup container, int position) {
//
//			if (views[position] == null) {
//				switch (position) {
//				case 0:
//					views[0] = inflater.inflate(R.layout.calorie_calculator,
//							null);
//					break;
//				case 1:
//					views[1] = inflater.inflate(R.layout.myoneday_calendar,
//							null);
//					break;
//
//				}
//			}
//			container.addView(views[position]);
//			return views[position];
//		}
//
//		@Override
//		public void destroyItem(ViewGroup container, int position, Object object) {
//			container.removeView((View) object);
//		}
//	}

}
